#ifndef		_GRAPHICS_H_
#define		_GRAPHICS_H_

#include "Globals.h"
#include "VertexBuffer.h"
#include "Window.h"

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "dxguid.lib")

namespace Cartesia 
{


class CARTESIA_API TextureInfo
{
public:
	char * szFileName;
	char * pData;
	int mipLevels;
	uint colorKey;
	uint width;
	uint height;
	uint size;

	TextureInfo()
	{
		pData = NULL;
		szFileName = NULL;
		mipLevels  = 0;
		colorKey = 0;
		width  = 0;
		height = 0;
		size = 0;
	}
};

//------------------------------------------------------------------

class CARTESIA_API Graphics
{
	static D3DXMATRIX				_theMatrix;

	static LPDIRECT3D9				_d3d;
	static LPDIRECT3DDEVICE9		_device;
	static D3DDISPLAYMODE			_displayMode;
	static D3DFORMAT				_format;
	static D3DPRESENT_PARAMETERS	_params;
	static D3DCAPS9					_caps;
	
	static vector<LPDIRECT3DTEXTURE9>	_textures;
	static int							_iCurrentTextureId;

	static VertexBuffer<VertexColor, FVF_VERTEX_COLOR>		_VBColor;
	static VertexBuffer<VertexTexture, FVF_VERTEX_TEXTURE>	_VBTexture;

	static int		_width;
	static int		_height;
	static DWORD	_clearColor;
	static bool		_fullscreen;

public:

	Graphics(void);
	~Graphics(void);

	static int Startup(HINSTANCE hInstance, int width, int height);
	static int Shutdown();
	static void BeginScene();
	static void Clear();
	static void EndScene();
	static void Present();

	static void BindTexture(int uiTextureId);
	static void Draw(VertexColor * pVertexCollection, D3DPRIMITIVETYPE ePrimitive, uint vertices);
	static void Draw(VertexTexture * pVertexCollection, D3DPRIMITIVETYPE ePrimitive, uint vertices);
	static void SetColor(DWORD color);
	static void SetResolution(int width, int height);

	static bool LoadTexture(TextureInfo * pTextureInfo);
	static void LoadIdentity();
	static void Translate(float x, float y, float z);
	static void RotateX(float angle);
	static void RotateY(float angle);
	static void RotateZ(float angle);
	static unsigned int GetCurrentTextureId() { return _iCurrentTextureId; }

	static void SetProjectionPerspective();
	static void SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);

	static ID3DXMesh* CreateBox(float width, float height, float depth);
	static ID3DXMesh* CreateCylinder(float radius1, float radius2, float length, uint slices, int stacks);
	static ID3DXMesh* CreatePolygon(float length, uint sides);
	static ID3DXMesh* CreateSphere(float radius, uint slices, uint stacks);
	static ID3DXMesh* CreateTeapot();
	static ID3DXMesh* CreateTorus(float innerRadius, float outerRadius, uint sides, uint rings);
	static void DrawD3DXMesh(ID3DXMesh* pMesh);
};


} // end namespace Cartesia


#endif	// _GRAPHICS_H_
